package com.hxd.otc.dialog;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.utils.DataUtils;

/**
 * 加载框
 */
public class LoadingDialog extends Dialog {

    private TextView tv_info;

    public LoadingDialog(Context context) {
        super(context, R.style.CustomDialg);
        setContentView(R.layout.dlg_loading);
        getWindow().setGravity(Gravity.CENTER);
        getWindow().getAttributes().width = DataUtils.dp2px(context, 120);
        getWindow().getAttributes().height = DataUtils.dp2px(context, 120);
        tv_info = findViewById(R.id.tv_info);
    }

    public LoadingDialog setText(String text) {
        if (!TextUtils.isEmpty(text)) {
            tv_info.setVisibility(View.VISIBLE);
            tv_info.setText(text);
        }
        return this;
    }

    public LoadingDialog setCancelOutSide(boolean isCancel) {
        setCanceledOnTouchOutside(isCancel);
        return this;
    }


    /**
     * 设置是否可取消
     *
     * @param isCancel
     * @return
     */
    public LoadingDialog setCancel(boolean isCancel) {
        setCancelable(isCancel);
        return this;
    }

    @Override
    public void show() {
        dismiss();
        super.show();
    }
}

